<?php 

function getInvoice($clientID){
  // Define the parameters that will be used
  $foo0 = $clientID;

  // Build the system command that will be called
  $cmd='./../perllib/GetInvoiceList.pl '.EscapeShellArg($foo0);

  // Execute the shell command
  $returnval = exec($cmd, $output, $result); 

  if ($result == "626") { echo ("A fatal error occured!"); }
  
  else if ($result == "4") { echo ("There is no such file."); }

  else{

  //nested loop retrieving data from GetInvoiceList.pl
  for($x = 0; $x < (count((array)$output)/4); $x++){

      for($y = ($x*4); $y < ($x*4)+4; $y++){ 

          //Retrieve and split Invoice information from GetInvoiceList.pl
               $out = $output[$y]; 
             $name = strtok($out, "=");
             $value = strtok("");
           $invoiceX[$x][$name] = $value;

  include("globalVar.php");
  $word = $invoiceX[$x]["filePath"];
  $temp = str_replace("INVOICEROOT", $INVOICEROOT ,$word);
  $invoiceX[$x]["filePath"] = $temp;

                   } #Close inner loop
        } #Close outer loop

         return($invoiceX);
      }
}


?>
